package com.teach.config;

import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;

import org.apache.commons.codec.binary.Base64;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

/**
 * <pre>
 * TODO : 授权服务基层配置 config.auth.*
 * ClassName : com.teach.config.AuthConfig
 * Author : J.L.Zhou
 * Date : 2020-03-04 12:08
 * Version : V1.0
 * Copyright 2020 jlzhou.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes
 * </pre>
 */
@Configuration
@ConfigurationProperties(prefix = "config.zuul", ignoreInvalidFields = true, ignoreUnknownFields = true)
@Data
public class ZuulConfigProperies {

	/**
	 * TODO 不需要进行身份认证的路径正在表达式
	 */
	public String[] skips;
	

	public Jwt jwt = new Jwt();

	public static class Jwt {

		/**
		 * 128个字符的秘钥字符
		 */
		@Getter
		private String key = "022bdc63c3c5a45879ee6581508b9d03adfec4a4658c0ab3d722e50c91a351c42c231cf43bb8f86998202bd301ec52239a74fc0c9a9aeccce604743367c9646b";

		/**
		 * 有效期30分钟 1000*60*30;
		 */
		@Getter
		@Setter
		public long expiration = 1000*60*30;
		
		/**
		 * 秘钥
		 */
		@Getter
		private SecretKey secretKey;
		
		public Jwt() {
			generalKey();
		}
		
		/**
		 * 生成密钥
		 */
		public void generalKey() {
			byte[] encodedKey = Base64.decodeBase64(key);
			secretKey = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES");
		}

		public void setKey(String key) {
			this.key = key;
			generalKey();
		}



		
		
		
	}
	

}
